package net.lab1024.sa.admin.module.business.goods.controller;

import lombok.RequiredArgsConstructor;
import net.lab1024.sa.admin.module.business.goods.service.StockService;
import net.lab1024.sa.base.common.annoation.NoNeedLogin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/stock")
@RequiredArgsConstructor
public class StockController {

    private final StockService stockService;

    /**
     * 扣减库存接口（供ApiPost调用）
     * @param productId 商品ID（默认1001）
     * @return 操作结果
     */
    @GetMapping("/decrease")
    @NoNeedLogin
    public String decreaseStock(@RequestParam(defaultValue = "1001") Long productId) {
        boolean success = stockService.decreaseStock(productId);
        return success ? "库存扣减成功" : "库存扣减失败（库存不足）";
    }
}